#include "jsontool.h"
#include <QMetaObject>
#include <QMetaProperty>

JsonTool::JsonTool()
{

}

QString JsonTool::success(const Entity& entity)
{
    QJsonObject programmerObject;
    programmerObject.insert(QStringLiteral("code"), 0);
    programmerObject.insert(QStringLiteral("msg"), "");
    programmerObject.insert(QStringLiteral("data"), entity.toJsonObject());
    return QJsonDocument(programmerObject).toJson(QJsonDocument::Compact);
}

QString JsonTool::success(const QVector<Entity> &entityVector)
{
    QJsonObject programmerObject;
    programmerObject.insert(QStringLiteral("code"), 0);
    programmerObject.insert(QStringLiteral("msg"), "");
    QJsonArray jsonArray;
    for(int i=0;i< entityVector.size();i++)
    {
        jsonArray.append(entityVector.at(i).toJsonObject());
    }
    programmerObject.insert(QStringLiteral("data"), jsonArray);
    return QJsonDocument(programmerObject).toJson(QJsonDocument::Compact);
}

QString JsonTool::success(const QJsonArray &array)
{
    QJsonObject programmerObject;
    programmerObject.insert(QStringLiteral("code"), 0);
    programmerObject.insert(QStringLiteral("msg"), "");
    programmerObject.insert(QStringLiteral("data"), array);
    return QJsonDocument(programmerObject).toJson(QJsonDocument::Compact);
}

QString JsonTool::success(const QJsonObject &jsonObject)
{
    QJsonObject programmerObject;
    programmerObject.insert(QStringLiteral("code"), 0);
    programmerObject.insert(QStringLiteral("msg"), "");
    programmerObject.insert(QStringLiteral("data"), jsonObject);
    return QJsonDocument(programmerObject).toJson(QJsonDocument::Compact);
}

QString JsonTool::success(QString data)
{
    QJsonObject programmerObject;
    programmerObject.insert(QStringLiteral("code"), 0);
    programmerObject.insert(QStringLiteral("msg"), "");
    programmerObject.insert(QStringLiteral("data"), data);
    return QJsonDocument(programmerObject).toJson(QJsonDocument::Compact);
}

QString JsonTool::failed(int code, QString msg)
{
    QJsonObject programmerObject;
    programmerObject.insert(QStringLiteral("code"), code);
    programmerObject.insert(QStringLiteral("msg"), msg);
    programmerObject.insert(QStringLiteral("data"), "");
    return QJsonDocument(programmerObject).toJson(QJsonDocument::Compact);
}


